package qe.spider.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.convert.NumberChineseFormatter;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.NumberUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import qe.spider.MainSelect;
import qe.spider.grab.ParseThsPlate;
import qe.spider.grab.ParseThsStock;

import java.io.File;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static cn.hutool.core.date.DatePattern.NORM_TIME_FORMATTER;

@Slf4j
@Data
public class PlateList {
    private BigDecimal ttag;
    private String errcode;

    private Plates plates;

    public static Collection<Plate> mergeKPLPlates(Collection<Plate> jingXuanPlates, Collection<Plate> gaiNianPlates, Collection<Plate> hangYePlates) {
        BigDecimal jingEMin = new BigDecimal(100000000).multiply(new BigDecimal(MainSelect.factor.getPlateJingE()));

        List<Plate> fundTopJingXuan = jingXuanPlates.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTopJingXuan = jingXuanPlates.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTopJingXuan = jingXuanPlates.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> topJingXuan = new HashSet<>(CollUtil.intersection(fundTopJingXuan, speedTopJingXuan, zhangfuTopJingXuan));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】净额前{}且值>={}亿的精选板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTopJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】涨速前{}的精选板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTopJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】涨幅前{}的精选板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTopJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("【开盘啦】1-精选板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), topJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));


        List<Plate> fundTopGaiNian = gaiNianPlates.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTopGaiNian = gaiNianPlates.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTopGaiNian = gaiNianPlates.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> topGaiNian = new HashSet<>(CollUtil.intersection(fundTopGaiNian, speedTopGaiNian, zhangfuTopGaiNian));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】净额前{}且值>={}亿的概念板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTopGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】涨速前{}的概念板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTopGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】涨幅前{}的概念板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTopGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("【开盘啦】2-概念板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), topGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));

        List<Plate> fundTopHangYe = hangYePlates.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTopHangYe = hangYePlates.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTopHangYe = hangYePlates.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> topHangYe = new HashSet<>(CollUtil.intersection(fundTopHangYe, speedTopHangYe, zhangfuTopHangYe));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】净额前{}且值>={}亿的行业板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTopHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】涨速前{}的行业板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTopHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【开盘啦】涨幅前{}的行业板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTopHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("【开盘啦】3-行业板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), topHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));

        Set<Plate> all = Stream.of(topJingXuan, topGaiNian, topHangYe).flatMap(Collection::stream).collect(Collectors.toSet());//筛后交集的并集
        log.info("【（开盘啦）上榜板块】（精选、概念、行业top的并集）：{}", all.stream().map(Plate::getName).collect(Collectors.joining("; ")));
        if (!all.isEmpty()) {
            log.info("\r\n【【【      （开盘啦）最强板块      】】】\r\n{}\r\n{}\r\n{}\r\n\n",
                    topJingXuan.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t精选：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")),
                    topGaiNian.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t概念：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")),
                    topHangYe.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t行业：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")));
        }
        return all;
    }

    public static Collection<Plate> mergeTHSPlates(Collection<Plate> a, Collection<Plate> b) {
        BigDecimal jingEMin = new BigDecimal(100000000).multiply(new BigDecimal(MainSelect.factor.getPlateJingE()));
        List<Plate> fundTop = a.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTop = a.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTop = a.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> top = new HashSet<>(CollUtil.intersection(fundTop, speedTop, zhangfuTop));
        if (log.isDebugEnabled())
            log.debug("【同花顺】净额前{}且值>={}亿的概念板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTop.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【同花顺】涨速前{}的概念板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTop.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【同花顺】涨幅前{}的概念板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTop.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("【同花顺】1-概念板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), top.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));

        List<Plate> fundTopOther = b.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTopOther = b.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTopOther = b.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> topOther = new HashSet<>(CollUtil.intersection(fundTopOther, speedTopOther, zhangfuTopOther));
        if (log.isDebugEnabled())
            log.debug("【同花顺】净额前{}且值>={}亿的行业板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTopOther.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【同花顺】涨速前{}的行业板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTopOther.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("【同花顺】涨幅前{}的行业板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTopOther.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("【同花顺】2-行业板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), topOther.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));
        Set<Plate> all = Stream.concat(top.stream(), topOther.stream()).collect(Collectors.toSet());//筛后交集的并集
        log.info("【（同花顺）上榜板块】（概念、行业top的并集）：{}", all.stream().map(Plate::getName).collect(Collectors.joining("; ")));
        if (!all.isEmpty()) {
            log.info("\r\n【【【      （同花顺）最强板块      】】】\r\n{}\r\n{}\r\n\n",
                    top.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t概念：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")),
                    topOther.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t行业：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")));
        }
        return all;
    }

    public static Collection<Plate> mergePlates(Collection<Plate> jingXuanPlates, Collection<Plate> gaiNianPlates, Collection<Plate> hangYePlates) {
        BigDecimal jingEMin = new BigDecimal(100000000).multiply(new BigDecimal(MainSelect.factor.getPlateJingE()));

        List<Plate> fundTopJingXuan = jingXuanPlates.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTopJingXuan = jingXuanPlates.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTopJingXuan = jingXuanPlates.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> topJingXuan = new HashSet<>(CollUtil.intersection(fundTopJingXuan, speedTopJingXuan, zhangfuTopJingXuan));
        if (log.isDebugEnabled())
            log.debug("净额前{}且值>={}亿的精选板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTopJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("涨速前{}的精选板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTopJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("涨幅前{}的精选板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTopJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("1-精选板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), topJingXuan.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));


        List<Plate> fundTopGaiNian = gaiNianPlates.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTopGaiNian = gaiNianPlates.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTopGaiNian = gaiNianPlates.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> topGaiNian = new HashSet<>(CollUtil.intersection(fundTopGaiNian, speedTopGaiNian, zhangfuTopGaiNian));
        if (log.isDebugEnabled())
            log.debug("净额前{}且值>={}亿的概念板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTopGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("涨速前{}的概念板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTopGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("涨幅前{}的概念板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTopGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("2-概念板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), topGaiNian.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));

        List<Plate> fundTopHangYe = hangYePlates.stream().filter(p -> p.getZhuLiJingE() != null && NumberUtil.isGreaterOrEqual(p.getZhuLiJingE(), jingEMin)).sorted(Comparator.comparing(Plate::getZhuLiJingE).reversed()).limit(MainSelect.factor.getPlateJingETopN()).collect(Collectors.toList());
        List<Plate> speedTopHangYe = hangYePlates.stream().filter(p -> p.getZhangSu() != null && p.getZhangSu().doubleValue() >= MainSelect.factor.getPlateZhangSu()).sorted(Comparator.comparing(Plate::getZhangSu).reversed()).limit(MainSelect.factor.getPlateZhangSuTopN()).collect(Collectors.toList());
        List<Plate> zhangfuTopHangYe = hangYePlates.stream().filter(p -> p.getZhangFu() != null && p.getZhangFu().doubleValue() >= MainSelect.factor.getPlateZhangFu()).sorted(Comparator.comparing(Plate::getZhangFu).reversed()).limit(MainSelect.factor.getPlateZhangFuTopN()).collect(Collectors.toList());
        Collection<Plate> topHangYe = new HashSet<>(CollUtil.intersection(fundTopHangYe, speedTopHangYe, zhangfuTopHangYe));
        if (log.isDebugEnabled())
            log.debug("净额前{}且值>={}亿的行业板块：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateJingE(), fundTopHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("涨速前{}的行业板块：{}", MainSelect.factor.getPlateZhangSuTopN(), speedTopHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu()).collect(Collectors.joining("; ")));
        if (log.isDebugEnabled())
            log.debug("涨幅前{}的行业板块：{}", MainSelect.factor.getPlateZhangFuTopN(), zhangfuTopHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):涨幅" + p.getZhangFu()).collect(Collectors.joining("; ")));
        log.info("3-行业板块净额前{}、涨速前{}、涨幅前{}交集：{}", MainSelect.factor.getPlateJingETopN(), MainSelect.factor.getPlateZhangSuTopN(), MainSelect.factor.getPlateZhangFuTopN(), topHangYe.stream().map(p -> p.getName() + "(" + p.getCode() + "):净额（" + NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue()) + "）=" + p.getZhuLiJingE() + ",涨速=" + p.getZhangSu() + ",涨幅=" + p.getZhangFu()).collect(Collectors.joining("; ")));

        Set<Plate> all = Stream.of(topJingXuan, topGaiNian, topHangYe).flatMap(Collection::stream).collect(Collectors.toSet());//筛后交集的并集
        log.info("【上榜板块】（精选、概念、行业top的并集）：{}", all.stream().map(Plate::getName).collect(Collectors.joining("; ")));
        if (!all.isEmpty()) {
            log.info("\r\n【【【      最强板块      】】】\r\n{}\r\n{}\r\n{}\r\n\n",
                    topJingXuan.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t精选：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")),
                    topGaiNian.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t概念：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")),
                    topHangYe.stream().map(p -> DateUtil.format(p.getGrabTime(), NORM_TIME_FORMATTER) + "\t行业：\t" + p.getName() + "\t\t净额：" + (p.getZhuLiJingE() == null ? "" : NumberChineseFormatter.formatSimple(p.getZhuLiJingE().longValue())) + "\t净量：" + (p.getZhulijingliang() == null ? "" : NumberUtil.decimalFormat("#.##%", p.getZhulijingliang())) + "\t涨速：" + p.getZhangSu() + "%\t涨幅：" + p.getZhangFu() + "%").collect(Collectors.joining("\r\n")));
        }
        return all;
    }
}
